/*
package com.young.shop.admin.filter;

import com.young.shop.admin.service.ViewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.context.support.XmlWebApplicationContext;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
@WebFilter("/*")
public class ViewsFilter implements Filter {

    @Autowired
    private ViewsService viewsService;

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("进入过滤器");

        HttpServletRequest req = (HttpServletRequest)servletRequest;
        HttpServletResponse resp = (HttpServletResponse)servletResponse;
        ServletContext sc = req.getSession().getServletContext();
        XmlWebApplicationContext cxt = (XmlWebApplicationContext) WebApplicationContextUtils.getWebApplicationContext(sc);
        String requestURI = req.getRequestURI();

        if(cxt != null && cxt.getBean("viewsService") != null && viewsService == null) {
            viewsService = (ViewsService) cxt.getBean("usersService");
            if(requestURI.contains("analyse")){
                //进入商品详细，增加浏览量
                this.viewsService.updateViews();
            }
        }
        filterChain.doFilter(servletRequest,servletResponse);
    }
}*/
